(function(window, undefined) {
	var Feed = {};
	window.Feed = window.Feed || Feed;
	
	Feed.loadMyFeed = function(){
		var selector = 'ul.talkList';
		var _user_id = sessionStorage.getItem('user_id');
		$.ajax({
			type : "post",
			url : ajaxURL + "feed.php?action=loadMyFeed",
			dataType:"json",
			data : {user_id : _user_id,row:Paging.getCurrent()},
			success : function(result) {
				$(selector).empty();
				$.each(result.data,function(){
					if(this.store_image==null||this.store_image==''){
						this.store_image='images/default_store.png';
					}
					
					if(this.user_image==null||this.user_image==''){
						this.user_image='images/default_user.png';
					}
					template.myFeed(this,selector);	
					
				});
				var _para = {
					dataLength : result.dataLength,
					// dataLength : 1000,
					selector : '#pagination > ul',
					callback : function(){
						Feed.loadMyFeed();
					}
				};
				
				Paging.innerAJAX(_para);
	
					
			}
		});
	};
	
	var template={
		
		myFeed : function(result,selector) {
			if(result.notification_type=='post'){
				var info='';
				info+='<li>';
				if(result.notification_type=='post'){
					info+='<div class="type talk"></div>';
				}else if(result.notification_type=='comment'){
					info+='<div class="type comment"></div>';
				}
				
				info+='<div class="thumbWrap small">';
				info+='<a href="store_view.php?id='+result.target_id+'">';
				info+='<img src="'+result.store_image+'" alt="thumb_store_1"></a></div>';
				info+='<div class="infoWrap">';
				info+='<a class="title" href="store_view.php?id='+result.target_id+'"><b>'+result.store_name+'</b>'+result.msg+'</a>';
				info+='<div class="storeInfo left">';
				info+='만족도 <b>'+result.satisfaction+'%</b> 단골수 <b>'+result.favorite_count+'</b>명</div> <div class="tags left">'+result.category_name+' <span>|</span> '+result.storeAddr2+'</div>';
				info+='<div class="date">'+result.created_date+'</div></div></li>';
				$(selector).append(info);
			}else if(result.notification_type=='add_coupon' || result.notification_type=='cast'){
				var info='';
				info+='<li>';
				if(result.notification_type=='add_coupon'){
					info+='<div class="type coupon"></div>';
					info+='<div class="infoWrap">';
					info+='<a class="title" href="#"><b>'+result.target_name+'</b>'+result.msg+'</a>';

				}else if(result.notification_type=='cast'){
					info+='<div class="type cast"></div>';
					info+='<div class="infoWrap">';
					info+='<a class="title" href="cast_view.php?id='+result.target_id+'"><b>'+result.target_name+'</b>'+result.msg+'</a>';

				}
				info+='<div class="date">'+result.created_date+'</div></div></li>';
				$(selector).append(info);
			}else if(result.notification_type=='stanby' || result.notification_type=='friend' || result.notification_type=='comment'){
				
				var info='';
				info+='<li>';
				info+='<div class="type friend"></div>';
				info+='<div class="thumbWrap small">';
				info+='<a href="people_view.php?id='+result.target_id+'">';
				info+='<img src="'+result.user_image+'" alt="thumb_store_1"></a></div>';
				info+='<div class="infoWrap">';
				if(result.notification_type=='comment'){
					info+='<a class="title" href="store_view.php?id='+result.store_id+'">';
				}else{
					info+='<a class="title" href="people_view.php?id='+result.target_id+'">';
				}
				info+='<b>'+result.target_name+'</b>'+result.msg+'</a>';
				info+='<div class="storeInfo left">';
				info+='활동지수 <b>'+result.activity_point+'</b> 리뷰 <b>'+result.talk_count+'</b>개  유용해요 <b>'+result.useful_count+'</b>번</div>';
				info+='<div class="date">'+result.created_date+'</div></div></li>';
				$(selector).append(info);
			}else if(result.notification_type=='favorite'){
				var info='';
				info+='<li>';
				info+='<div class="type store"></div>';
				info+='<div class="thumbWrap small">';
				info+='<a href="store_view.php?id='+result.target_id+'">';
				info+='<img src="'+result.store_image+'" alt="thumb_store_1"></a></div>';
				info+='<div class="infoWrap">';
				info+='<a class="title" href="store_view.php?id='+result.target_id+'"><b>'+result.store_name+'</b>'+result.msg+'</a>';
				info+='<div class="storeInfo left">';
				info+='만족도 <b>'+result.satisfaction+'%</b> 단골수 <b>'+result.favorite_count+'</b>명</div> <div class="tags left">'+result.category_name+' <span>|</span> '+result.storeAddr2+'</div>';
				info+='<div class="date">'+result.created_date+'</div></div></li>';
				$(selector).append(info);
			}else if(result.notification_type=='message'){
				var info='';
				info+='<li>';
				info+='<div class="type message"></div>';
				info+='<div class="infoWrap">';
				info+='<a class="title" href="store_view.php?id='+result.target_id+'"><b>'+result.sender_name+'</b>'+result.msg+'</a>';
				info+='<div class="date">'+result.created_date+'</div></div>';
				info+='<div class="commentWrap"><p>'+result.message+'</p></div>';
				info+='</li>';
				$(selector).append(info);
			}
		}
	}
		
})(window);
